package com.szd.qiongyou20.home.search.result_fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.szd.qiongyou20.R;
import com.szd.qiongyou20.home.search.adapter.Jn_ListView_Adapter;
import com.szd.qiongyou20.home.search.bean.JnBean;
import com.szd.qiongyou20.home.search.presenter.JnPre;
import com.szd.qiongyou20.home.search.view.JnDataToView;

import java.util.List;

/**
 * Created by SZD on 2016/12/26.
 */

public class Jn_Fragment extends Fragment implements JnDataToView {

    private Context mContext;
    private ListView mListView;
    private String mKeyword;
    private JnPre mJnPre;

    public static Jn_Fragment newInstance(String keyword) {
        Bundle bundle = new Bundle();
        Jn_Fragment fragment = new Jn_Fragment();
        bundle.putString("keyword", keyword);
        fragment.setArguments(bundle);
        return fragment;

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();

        mKeyword = getArguments().getString("keyword");
        mJnPre = new JnPre(this, mKeyword);
        mJnPre.loadDataToView();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.listview_search, null);
        mListView = (ListView) view.findViewById(R.id.listView_result);
        return view;
    }


    @Override
    public void DataToView(JnBean jnBean) {
        List<JnBean.DataBean.EntryBean> entry = jnBean.getData().getEntry();
        Jn_ListView_Adapter adapter =
                new Jn_ListView_Adapter(mContext, entry);
        mListView.setAdapter(adapter);
    }
}
